//
//  GKDYVideoViewModel.m
//  GKDYVideo
//
//  Created by grx on 2018/9/23.
//  Copyright © 2018 grx. All rights reserved.
//

#import "LYouVideoViewModel.h"

@interface LYouVideoViewModel()

// 页码
@property (nonatomic, assign) NSInteger pn;

@end

@implementation LYouVideoViewModel

- (void)refreshNewListWithSuccess:(void (^)(NSArray * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    self.pn = 1;
    
    [self videoListRequestWithSuccess:success failure:failure];
}

- (void)refreshMoreListWithSuccess:(void (^)(NSArray * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    self.pn ++;
    
    [self videoListRequestWithSuccess:success failure:failure];
}

- (void)videoListRequestWithSuccess:(void (^)(NSArray * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    NSMutableDictionary *params = [NSMutableDictionary new];
    // 推荐列表
    NSString *url = [NSString stringWithFormat:@"%@/recommend",LYBASEURL];
    [[LYouNetClient sharedInstance]NetRequestGETWithRequestURL:url WithParameter:params WithReturnValeuBlock:^(NSURLSessionDataTask *task,id  _Nullable responseObject,NSArray *responseArray) {
        NSLog(@"responseDict=======%@",responseArray);
        NSMutableArray *allArray = [NSMutableArray new];
        /** 解析数组 */
        for (NSDictionary *dic in responseArray) {
            LYouVideoModel *model = [[LYouVideoModel alloc]init];
            model.post_id = [NSString stringWithFormat:@"%@",dic[@"id"]];
            model.video_url = [NSString stringWithFormat:@"%@",dic[@"video"]];
            model.thumbnail_url = [NSString stringWithFormat:@"%@",dic[@"cover"]];
            [allArray addObject:model];
        }
        success([allArray copy]);
    } WithErrorBlock:^(NSURLSessionDataTask *task, NSError *error) {
        [LYouLoadingView hide];
        failure(error);
    } WithFailureBlock:^{
        [LYouLoadingView hide];
    }];
}

@end
